<extend name="public:base" />

<block name="left">
	<div class="mark_bar cl">
		<a href="{:url('uc/promotion/index')}" class="goback fl"><i class="iconfont">&#xe600;</i></a>
		<p>发红包</p>
		<notempty name="friends_list">
			<a href="javascript:void(0)" class="btm" id="allSend">全选发送</a>
			<a href="javascript:void(0)" class="btm" style="display: none;" id="cancel">取消</a>
		</notempty>
	</div>
</block>

<block name="main">
	<div class="container">
		<div class="promotionPackets">
			<notempty name="friends_list">
				<div class="title">
					<p>红包发送规则：用户可给您的好友发放红包，金额随机；</p>
					<p class="af60">（每周同一个好友限发1个）</p>
				</div>
				<div class="selectContent ones">
					<ul class="friendList">
						<volist name="friends_list" id="v">
							<if condition="$v.rank eq 1">
							<li>
								<span class="number">{$v.user_phone|substr=0,3}****{$v.user_phone|substr=7,4}</span>

								<if condition="$v.send_card eq 1">
									<button type="button" class="submit sendPackets" data-id="{$v.id}" data-name="{$v.user_phone|substr=0,3}****{$v.user_phone|substr=7,4}">发红包</button>
									<else/>
									<button type="button" class="submit sendPackets dis" disabled>已发送</button>
								</if>
							</li>
							</if>
						</volist>
					</ul>
				</div>
				<div class="selectContent multiselect hide">
					<ul class="friendList">
						<volist name="friends_list" id="v">
							<if condition="$v.rank eq 1">
							<li>
								<label>
									<input type="checkbox" name="f1" value="{$v.id}" <if condition="$v.send_card neq 1">disabled</if> />
									<span class="number">{$v.user_phone|substr=0,3}****{$v.user_phone|substr=7,4}</span>
								</label>
							</li>
							</if>
						</volist>
					</ul>
					<div class="submitLine">
						<button type="button" class="submit sendPackets" id="multiselectBtn">发红包</button>
					</div>
				</div>
				<else/>
				<div class="empty">暂无好友信息</div>
			</notempty>
		</div>
	</div>
</block>

<block name="menu"></block>

<block name="js">
	<script type="text/javascript">
		var all = "#allSend",one = "#cancel",selectones = ".selectContent.ones",multiselect = ".selectContent.multiselect";
		$(all).click(function () {
			$(this).hide().siblings(one).show();
			$(selectones).addClass("hide");
			$(multiselect).removeClass("hide");
        });
        $(one).click(function () {
            $(this).hide().siblings(all).show();
            $(multiselect).addClass("hide");
            $(selectones).removeClass("hide");
        });

		$("#multiselectBtn").click(function () {
            var checked = [],checked_input = $(".selectContent.multiselect").find("input[type=checkbox]:checked");
            checked_input.each(function () {
                checked.push($(this).val());
            });
            if(checked.length <= 0) return false;
            layer.open({
                content: '您确定要给这' + checked.length + '名好友发送红包吗？'
                ,btn: ['确定', '取消']
                ,yes: function(){
                    $.post("{:url('uc/promotion/send_card')}",{friend_id : checked.toString()},function (d) {
                        layer.closeAll();
                        if(d.code === 1){
                            wjtips(d.msg);
                            setTimeout(function () {
								window.location.reload();
                            },1500);
                        }else{
                            wjtips(d.msg);
                        }
                    },"json");
                }
            });
        });

        $(".sendPackets").click(function (){
            var id = $(this).attr("data-id"),user_name = $(this).attr("data-name");
            if(!id) return false;
            layer.open({
                content: '您确定要给这' + user_name + '名好友发送红包吗？'
                ,btn: ['确定', '取消']
                ,yes: function(){
                    $.post("{:url('uc/promotion/send_card')}",{friend_id : id.toString()},function (d) {
                        layer.closeAll();
                        if(d.code === 1){
                            wjtips(d.msg);
                            $(this).prop("disabled",true).addClass("dis");
                        }else{
                            wjtips(d.msg);
                            $(this).prop("disabled",false).removeClass("dis");
                        }
                    },"json");
                }
            });

        });


	</script>
</block>